/*
 * @Author: RAY_HUI 1541917867@qq.com
 * @Date: 2025-08-01 14:15:35
 * @LastEditors: 稽辉 liang_hui@petalmail.com
 * @LastEditTime: 2025-10-12 20:59:27
 * @FilePath: \website-reconstruction-vue\src\stores\langStore.ts
 * @Description:
 *
 * Copyright (c) 2025 by ${git_name_email}, All Rights Reserved.
 */
// stores/langStore.ts
import { defineStore } from 'pinia'
import { debounce } from 'lodash-es' // 或直接 import _ from 'lodash'
interface LangState {
  currentLang: 'zh' | 'en'
}

export const useLangStore = defineStore('lang', {
  state: () => ({
    currentLang: 'zh' as 'zh' | 'en',
    tipsButton: '发现更多' as '发现更多' | 'Find More',
    productTypeId: 0 as number,
    // HeaderString: '' as string,
    brandId: 0 as number,
    parentId: 0 as number,
  }),

  actions: {
    toggleLanguage: debounce(
      function (this: any) {
        this.currentLang = this.currentLang === 'zh' ? 'en' : 'zh'
        // console.log('最终切换:', this.currentLang)
        // 这里可以添加API请求等副作用
        this.tipsButton =
          this.tipsButton === '发现更多' ? 'Find More' : '发现更多'
        // console.log('通用按钮文本转换成了', this.tipsButton)
      },
      300,
      { leading: false, trailing: true }
    ),
    chageProductTypeAndBrandIdAndParentId: function (
      this: any,
      productTypeId,
      brandId,
      parentId
    ) {
      this.productTypeId = productTypeId
      this.brandId = brandId
      this.parentId = parentId
    },
    // 可选：清理防抖的方法
    cancelPendingToggle() {
      // @ts-ignore
      this.toggleLanguage.cancel?.()
    },
  },
})
export type LangStore = ReturnType<typeof useLangStore>
